<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2018/6/13
 * Time: 10:40
 */
namespace app\api\controller;
use think\Controller;
use think\Db;
use Qiniu\Auth;
class  Base extends Controller {
    protected $_error;
    protected $_header;//用户的请求头信息
    protected $otherLogin  = '您的账号已在其他设备登录';
    protected $frost = '您的账号已被冻结';
    protected $del = '您的账号已注销';
    // 构造函数 数据类型最大到6了
    public function _initialize(){
        // 如果配置项为空 则直接返回

    }

    /**
     * 验证唯一——单点登录
     * user_id，time，salt，value
     * @return string
     */
    public  function checkAll($uid,$time,$value,$reqKey){
        if($uid == 0) {
            return 111;
        } else {
            $user = Db::table('up_u_user')->where('user_id',$uid)->find();
            if($user['user_status'] == 2){ // 冻结
                return 110;
            }
            if($user['user_status'] == 3){ // 删除
                return 1103;
            }
            $token = $user['user_token'];
            $appId = "F20201279836621";
            $appkey = "9FM807G0-MF12-J521-6998-6D57N0GHN8BV";
            $myreqKey = md5($appId . 'XW' . $appkey . 'XW' . $time);
            $myvalue = md5($uid . 'XW' . $token . 'XW' . $time);
            if($myvalue != $value || $myreqKey != $reqKey) {
                return 112;
            } else {
                return 111;
            }
        }
    }
    /**
     * 获取uuid
     * @param string $prefix
     * @return string
     */
    public function uuid($prefix = '')
    {
        $chars = md5(uniqid(mt_rand(), true));
        $uuid  = substr($chars,0,8);
        $uuid .= substr($chars,8,4);
        $uuid .= substr($chars,12,4);
        $uuid .= substr($chars,16,4);
        $uuid .= substr($chars,20,12);
        return $prefix . $uuid;
    }
    /**
     * 获取七牛token
     * @return string
     */
    public function getQiniuToken(){
        require_once ('../extend/qiniu/autoload.php');
        header("Access-Control-Allow-Origin:*");
        $accessKey = config('qiniu')['accessKey'];
        $secretKey = config('qiniu')['secretKey'];
        $bucket = config('qiniu')['bucket'];
//        $auth = new Qiniu();
        $auth = new Auth($accessKey, $secretKey);
        $token = $auth->uploadToken($bucket);
        return json_encode(array('data'=>$token));
    }
    /**
     * param $tmp
     * param $name
     * param $size
     * 上传图片
     */
//    public function uploadFile($tmp,$name,$size)
    public function uploadFile()
    {
        $tmp = $_FILES['image']['tmp_name'];
        $name = $_FILES['image']['name'];
        $size = $_FILES['image']['size'];
        if($size > 1024*1024*5){
            return json_encode(['status'=>0,'msg'=>"图片不得超过5M！"]);
        }
        $imgarray = array('jpg','jpeg','png');
        $dir = $_SERVER['DOCUMENT_ROOT'];
        $url =  "http://".$_SERVER['HTTP_HOST'];
        if($tmp){
            //=======重命名=====
            $rand = date('YmdHis').rand(100000,999999);
            $exe = explode('.',$name);
            $exe = end($exe);
//            if(!in_array($exe,$imgarray)){
//                return json_encode(['status'=>0,'msg'=>'图片格式不支持']);
//            }
//            $newName = $rand . '.' .$exe;
            $newName = $rand . '.png';
            //=======================
            if(move_uploaded_file($tmp,"{$dir}/image/{$newName}")){
                $imgUrl = "{$url}/image/{$newName}";
                if($size > 1024*1024*2){
                    $this->image_png_size_add("{$dir}/image/{$newName}","{$dir}/image/{$newName}");
                }
                return json_encode(['status'=>200,'msg'=>$imgUrl]);
            }else{
                return json_encode(['status'=>0,'msg'=>'图片保存失败']);
            }
        }else{
            return json_encode(['status'=>0,'msg'=>"上传一张图！"]);
        }
    }

    /**
     * 压缩图片
     * @param $imgsrc:原图片地址（完整的图片路径）
     * @param $imgdst:压缩后的图片地址，也是完整的
     */
    function image_png_size_add($imgsrc,$imgdst){
        list($width,$height,$type)=getimagesize($imgsrc);
        switch($type){
            case 1:
                break;
            case 2:
                header('Content-Type:image/jpeg');
                $image = imagecreatefromjpeg($imgsrc);
                imagejpeg($image, $imgdst,20);
                imagedestroy($image);
                break;
            case 3:
                header('Content-Type:image/png');
                $image = imagecreatefrompng($imgsrc);
                imagejpeg($image, $imgdst,20);
                imagedestroy($image);
                break;
        }
    }

    /**
     * formatTime 时间格式化
     * @param $time 时间戳
     * @return string
     */
    public function formatTime($time) {
        $now_time = time();
        $t = $now_time - $time;
        $yea = (int) ($t / (86400 * 30 * 12));
        if ($yea >= 1) {
            return $yea.'年前';
        }
        $mon = (int) ($t / (86400 * 30));
        if ($mon >= 1) {
            return '一个月前';
        }
        $day = (int) ($t / 86400);
        if ($day >= 1) {
            return $day . '天前';
        }
        $h = (int) ($t / 3600);
        if ($h >= 1) {
            return $h . '小时前';
        }
        $min = (int)($t / 60);
        if ($min >= 1) {
            return $min . '分钟前';
        }
        return '刚刚';
    }

    /**
     * 获取任意长度的随机字符串
     * @param $length
     * @return string
     */
//    function getRandChar($length)
//    {
//        $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
//            'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
//            't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
//            'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
//            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
//            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
//        $char_txt = '';
//        for ($i = 0; $i < $length; $i++) {
//            $char_txt .= $chars[array_rand($chars)];
//        }
//        return $char_txt;
//    }

    /**
     * 验证码
     * @param $length
     * @return string
     */
    function getCodeChar($length)
    {
        $chars = array(
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $char_txt = '';
        for ($i = 0; $i < $length; $i++) {
            $char_txt .= $chars[array_rand($chars)];
        }
        return $char_txt;
    }
    public function getAcount()
    {
        //==========base里放到===============
        $zimu = range('a','z');
        $one = rand(0,25);
        $two = rand(0,25);
        $thr = rand(0,25);
        $four = rand(0,25);
        $zimu2 = $zimu[$one].$zimu[$two].$zimu[$thr].$zimu[$four];
        $num = rand(100000,999999);
        return $zimu2.$num;
        //=========================
    }

    //------------------------mww-------------------------------------------------------
    /**
     * 预约和拜访时间上不能冲突
     */
    public function canVisitMeet($uid,$start,$end)
    {
        $have1 = Db::table('up_visit')
            ->where('v_ask_uid',$uid)
            ->where('v_ask_status','in','1,2')
            ->where('v_take_status','in','1,2')
            ->where('v_start','<',$start)
            ->where('v_end','>',$start)
            ->find();
        $have2 = Db::table('up_visit')
            ->where('v_ask_uid',$uid)
            ->where('v_ask_status','in','1,2')
            ->where('v_take_status','in','1,2')
            ->where('v_start','<',$end)
            ->where('v_end','>',$end)
            ->find();
        $where = [
            'mu_user_id' => $uid,
            'm_del' => 1,
            'm_status' => ['in','1,2'],
            'mu_status' => ['in','1,2'],
        ];
        $have3 = Db::table('up_meeting_user')->alias('mu')
            ->join('up_meeting m','mu.mu_m_id = m.m_id','left')
            ->join('up_u_user u','m.m_user_id = u.user_id','left')
            ->where($where)
            ->where('m_start','<',$start)
            ->where('m_end','>',$start)
            ->field('m.m_id')
            ->find();
        $have4 = Db::table('up_meeting_user')->alias('mu')
            ->join('up_meeting m','mu.mu_m_id = m.m_id','left')
            ->join('up_u_user u','m.m_user_id = u.user_id','left')
            ->where($where)
            ->where('m_start','<',$end)
            ->where('m_end','>',$end)
            ->field('m.m_id')
            ->find();
        if($have1 || $have2 || $have3 || $have4){
            return false;
        }else{
            return true;
        }
    }
    /**
     * 极光推送
     * @param $type 1:推送个人  2:推送全体
     * @param $alias 别名 user_id OR token
     * @param $message 推送消息内容
     * @param $extras 扩展字段接受数组
     * 1拜访  2会议  3sae  4提问  5系统  6资料发布
     * @return array
     */
    public function Jpush($type,$alias,$message,$extras)
    {
        if(is_string($alias) || is_int($alias)){
            $alias = (string)$alias;
        }
        if(is_array($alias)){
            foreach ($alias as $k => $v) {
                $val = (string)$v;
                $alias[$k] = $val;
            }
        }
        import('jpush.autoload', EXTEND_PATH);
        //初始化JPushClient
        $client = new \JPush\Client(config('jpush.appKey'),config('jpush.masterSecret'));
        //生成推送Payload构建器
        $push = $client->push();
        //推送平台 'all'  OR  ['ios','android']  OR  'ios','android'
        $push->setPlatform('all');
        //1:推送个人  2:推送全体
        if($type==1){
            $push->addAlias($alias);//按别名推送
        }else{
            $push->addAllAudience();//广播消息推送
        }
        //IOS推送
        $push->iosNotification($message, [
                'alert'=>$message,
                'badge' => '+1',
                'extras' => $extras,
                'sound'=>'default'
            ]
        );
        //Android推送
        $push->androidNotification($message, [
                'alert'=>$message,
                'extras' => $extras
            ]
        );
        $push->message($message, [
//            'title' => 'Hello',
            'content_type' => 'text',
            'extras' => $extras
        ]);
        return $push->send();
    }
    //-------------------------------------腾讯建群操作 start -------------------------------------------
    //建群
    public function create($user_id,$groupid,$name,$users=[],$usersig){
        $data = [
            'Owner_Account' => "$user_id",
            'Type' => 'Public',
            'GroupId' => "$groupid",
            'Name' => $name
        ];
        if($users){
            $data['MemberList'] = $users;
        }
        $str = '?sdkappid=' . config('tengx')['appid'] . '&identifier=administrator&usersig='.$usersig.'&random='.mt_rand(100000,999999).'&contenttype=json';
        $url = 'https://console.tim.qq.com/v4/group_open_http_svc/create_group' . $str;
        $result = https_request($url,json_encode($data),'POST');
        $res = json_decode($result, true);
        return $res;
    }

    //加入
    /**
     * @return mixed
     */
    public function joinin($usersig,$groupid,$users)
    {
        $data = [
            'GroupId' => "$groupid",
            'Silence' => '1',
            'MemberList' => $users
        ];
        $str = '?sdkappid=' . config('tengx')['appid'] . '&identifier=administrator&usersig='.$usersig.'&random='.mt_rand(100000,999999).'&contenttype=json';
        $url = 'https://console.tim.qq.com/v4/group_open_http_svc/add_group_member' . $str;
        $result = https_request($url,json_encode($data),'POST');
        $res = json_decode($result, true);
        return $res;
    }

    //退出
    public function getout($usersig,$groupid,$users)
    {
        $data = [
            'GroupId' => "$groupid",
            'Silence' => '1',
            'MemberToDel_Account' => $users
        ];
        $str = '?sdkappid=' . config('tengx')['appid'] . '&identifier=administrator&usersig='.$usersig.'&random='.mt_rand(100000,999999).'&contenttype=json';
        $url = 'https://console.tim.qq.com/v4/group_open_http_svc/delete_group_member' . $str;
        $result = https_request($url,json_encode($data),'POST');
        $res = json_decode($result, true);
        return $res;
    }
    //解散
    public function kill($usersig,$groupid)
    {
        $data = [
            'GroupId' => "$groupid"
        ];
        $str = '?sdkappid=' . config('tengx')['appid'] . '&identifier=administrator&usersig='.$usersig.'&random='.mt_rand(100000,999999).'&contenttype=json';
        $url = 'https://console.tim.qq.com/v4/group_open_http_svc/destroy_group' . $str;
        $result = https_request($url,json_encode($data),'POST');
        $res = json_decode($result, true);
        return $res;
    }
    //编辑群名字
    public function editgroup($usersig,$groupid,$newname)
    {
        $data = [
            'GroupId' => "$groupid",
            'Name' => "$newname"
        ];
        $str = '?sdkappid=' . config('tengx')['appid'] . '&identifier=administrator&usersig='.$usersig.'&random='.mt_rand(100000,999999).'&contenttype=json';
        $url = 'https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info' . $str;
        $result = https_request($url,json_encode($data),'POST');
        $res = json_decode($result, true);
        return $res;
    }
    //--------------------------- 腾讯建群操作 end --------------------------------
    public function getUserInfo($user_id,$field='',$type=1)
    {
        if($field){
            if($type == 1){
                $res = Db::table('up_u_user')->where('user_id',$user_id)->value($field);
            }else{
                $res = Db::table('up_u_user')->where('user_id',$user_id)->field($field)->find();
            }
        }else{
            $res = Db::table('up_u_user')->where('user_id',$user_id)->find();
        }
        return $res;

    }
    //---------------------------- 日期 -----------------------------------------
    /**
     * startmonth
     * user_id
     * @return \think\response\Json
     */
    public function getMonthDays($month_date)
    {
//        $month_date = $_POST['startmonth'];
//        if(!$month_date){
//            $month_date = date('Y-m');
//        }
//        $month_date = '2020-12';
        $start_time = strtotime($month_date);
        $start_week = date('w', $start_time);
        $total_month_day = date('t', $start_time);
        $weeks_in_month = ceil(($start_week+$total_month_day)/7);
        $month_day_arr = [];
        $start_month_day = 1;
        $lastnum = 1;
        $kkk = 0;
        for($i=0;$i<$weeks_in_month;$i++) {
            for($j=0;$j<7;$j++){
                if($i ==0 && $j >= $start_week) {
                    $month_day_arr[$kkk] = $month_date . '-' . sprintf("%02d",$start_month_day);
                    $start_month_day++;
                } elseif($i == 0) {
                    $jjj = $start_week - $j;
                    $month_day_arr[$kkk] = date("Y-m-d",strtotime("$month_date -$jjj days"));
                } else {
                    $month_day_arr[$kkk] = $month_date . '-' . sprintf("%02d",$start_month_day);
                    if($start_month_day > $total_month_day){
                        $strdate = $month_date . '-' . $total_month_day;
                        $month_day_arr[$kkk] = date("Y-m-d",strtotime("$strdate +$lastnum days"));
                        $lastnum++;
                    }
                    $start_month_day++;
                }
                $kkk++;
            }
        }
//        dump($month_day_arr);die;
//        $have_str = '';
//        $have = Db::table('up_plan_practice')
//            ->where('pra_student',$_POST['user_id'])
//            ->where('pra_online',1)
//            ->column('pra_date');
//        if($have){
//            $have_str = implode($have,',');
//        }
        $prev = date('Y-m-d', strtotime($month_date . '-01 -1 month'));
        $next = date('Y-m-d', strtotime($month_date . '-01 +1 month'));
        return [ 'now' => $month_day_arr, 'prev' => $prev, 'next' => $next,  'today' => date('Y-m-d')];
        return json([ 'now' => $month_day_arr,  'today' => date('Y-m-d')]);
    }
    public function GetMonth()
    {
        //得到系统的年月
        $tmp_date=date("Ym");
        //切割出年份
        $tmp_year=substr($tmp_date,0,4);
        //切割出月份
        $tmp_mon =substr($tmp_date,4,2);
        $tmp_nextmonth=mktime(0,0,0,$tmp_mon+1,1,$tmp_year);
        $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-1,1,$tmp_year);
        $fm_next_month=date("Ym",$tmp_nextmonth);
        $fm_forward_month=date("Ym",$tmp_forwardmonth);
    }
    /**
     * startdate
     */
    public function getDays7($month_date)
    {
//        $month_date = $_POST['startdate'];
//        $month_date = '2020-12-24';
//        if(!$month_date){
//            $month_date = date('Y-m-d');
//        }
        $prev = $month_date;
        $start_time = strtotime($month_date);
        $start_week = date('w', $start_time);
        $total_month_day = date('t', $start_time);
        $weeks_in_month = ceil(($start_week+$total_month_day)/7);
        $month_day_arr = [];
        $start_month_day = date("d",strtotime("$month_date"));
        $days = 0;
        for($i=0;$i<2;$i++) {
            for($j=0;$j<7;$j++){
                if($i ==0 && $j >= $start_week) {
                    $month_day_arr[$i][$j] = date("Y-m-d",strtotime("$month_date +$days days"));
                    $start_month_day++;
                    $days++;
                } elseif($i == 0) {
                    $jjj = $start_week - $j;
                    if($j == 0){
                        $prev = date("Y-m-d",strtotime("$month_date -$jjj days"));
                    }
                    $month_day_arr[$i][$j] = date("Y-m-d",strtotime("$month_date -$jjj days"));
                } else {
                    $month_day_arr[$i][$j] = date("Y-m-d",strtotime("$month_date +$days days"));
                    $start_month_day++;
                    $days++;
                }
            }
        }

        $now = $month_day_arr[0];
        $next = $month_day_arr[1];
        $prevarray = [];
        for($i=1;$i<=7;$i++) {
            $ji = 8-$i;
            $prevarray[$i-1] = date("Y-m-d",strtotime("$prev -$ji days"));
        }
//        dump($month_day_arr);dump($prevarray);die;
        $before = date("Y-m-d",strtotime("$prevarray[0] -1 day"));
        $after = date("Y-m-d",strtotime("$next[6] +1 day"));
        $res = [
            'now' => $now, 'prev' => $prevarray, 'next' => $next, 'today' => date('Y-m-d')
            ,'before' => $before, 'after' => $after
        ];
        return $res;
        return json([
            'status' => 200, 'msg' => $now, 'prev' => $prevarray, 'next' => $next, 'today' => date('Y-m-d')
            ,'before' => $before, 'after' => $after
        ]);
    }
    public function getTodayInfo($month_date)
    {
        $tang = [
            1 => '一',
            2 => '二',
            3 => '三',
            4 => '四',
            5 => '五',
            6 => '六',
        ];
        $time = strtotime($month_date);
        $wk_day = date('w', strtotime(date('Y-m-1 00:00:00', $time))) ? : 7; //今天周几
        $day = date('d', $time) - (8 - $wk_day); //今天几号
        $y = date('Y',$time);
        $m = date('m',$time);
        $d = $day <= 0 ? 1 : ceil($day / 7) + 1; //计算是第几个星期
        $ymdstr = $y . '年' . $m . '月' . ' 第' . $tang[$d] . '周';
        return $ymdstr;
    }
    public function meetStatus()
    {
        $now = date('Y-m-d H:i:s');
        $have = Db::table('up_meeting')
            ->where('m_status', 1)
            ->where('m_start','<=',$now)
            ->field('m_id')
            ->find();
        if($have){
            Db::table('up_meeting')
                ->where('m_status', 1)
                ->where('m_start','<=',$now)
                ->setField('m_status',2);
        }
        $have = Db::table('up_meeting')
            ->where('m_status', 2)
            ->where('m_end','<=',$now)
            ->field('m_id')
            ->find();
        if($have){
            Db::table('up_meeting')
                ->where('m_status', 2)
                ->where('m_end','<=',$now)
                ->setField('m_status',3);
        }
        return true;
    }

    /**
     * foreach循环给字符串转数组
     * @return bool
     */
    public function foreachStrArr($data,$field,$readfield='',$user_id='',$table='',$table_id='',$zhuan_field='')
    {
        foreach ($data as $k => $v){
            //把图片切割成数组
            if($field){
                if($v[$field]){
                    $data[$k][$field] = explode(',',$v[$field]);
                }else{
                    $data[$k][$field] = [];
                }
            }
            //如果要判断已读未读，则操作一下
            if($readfield && $user_id){
                if(!strstr($v[$readfield],",$user_id,")){
                    $data[$k]['haveread'] = 1;
                    //----------------------未读改已读，列表处理 start --------------------------
                    $uids = $v[$readfield] . $user_id . ',';
                    Db::table($table)
                        ->where($table_id, $v[$table_id])
                        ->setField($readfield,$uids);
                    //----------------------未读改已读，列表处理 end --------------------------
                }else{
                    $data[$k]['haveread'] = 2;
                }
            }
            //如果要查看都转给谁了，则查一下
            if($zhuan_field){
                if($v[$zhuan_field]){
                    $uids = trim($v[$zhuan_field],',');
                    $zhuan_names = Db::table('up_u_user')
                        ->where('user_id', 'in',$uids)
                        ->column('user_username');
                    $data[$k]['zhuan_names'] = $zhuan_names;
                }
            }
        }
        return $data;
    }
    /**
     * 未更新改为已更新
     */
    public function editLikes($type,$id)
    {
        $have = Db::table('up_like_project')
            ->where('lpro_type',$type)
            ->where('lpro_prom_id',$id)
            ->where('lpro_edit',1)
            ->find();
        if($have){
            try{
                Db::table('up_like_project')
                    ->where('lpro_type',$type)
                    ->where('lpro_prom_id',$id)
                    ->where('lpro_edit',1)
                    ->setField('lpro_edit',2);
            }catch(\Exception $e){

            }

        }
        return true;
    }

    /**
     * @param $data
     * @param $user_id
     * @param $user_type
     * @param $user_shi
     * @param $type：1是单条数据   2是多条数据
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public function productRealCharger($cp_id,$user_id,$c_id)
    {
        $user = $this->getUserInfo($user_id,'user_type,user_hospital',2);
        $user_type = $user['user_type'];
        $user_hospital = $user['user_hospital'];
        if($user_type == 1){
            //如果我是用户，先找负责我所属区域的业务员，找不到就找对应区域的区域负责人
            $have = Db::table('up_user_charge')->alias('uc')
                ->join('up_u_user u','uc.uc_user_id=u.user_id','LEFT')
                ->where('uc_cp_id',$cp_id)
                ->where('user_status',1)
                ->where('user_auth',1)
                ->where('uc_names','like',"%,$user_hospital,%")
                ->field('user_id,user_username,user_image')
                ->find();
            if($have){
                return $have;
            }else{
                $have = Db::table('up_user_charge')->alias('uc')
                    ->join('up_u_user u','uc.uc_user_id=u.user_id','LEFT')
                    ->where('uc_cp_id',$cp_id)
                    ->where('user_status',1)
                    ->where('user_auth',2)
                    ->where('uc_names','like',"%,$user_hospital,%")
                    ->field('user_id,user_username,user_image')
                    ->find();
                if($have){
                    return $have;
                }else{
                    return [];
                }
            }

        }else{
            //如果我是区域负责人则不显示，
            //如果我是业务员，先看我有没有负责，如果我负责则不显示，
            //如果我没有负责，则找我所属区域的业务员，如果我负责的区域是多个，则找到同样覆盖多区域的业务员或者区域负责人

            $have = Db::table('up_user_charge')->alias('uc')
                ->join('up_u_user u','uc.uc_user_id=u.user_id','LEFT')
                ->where('uc_user_id',$user_id)
                ->where('uc_cp_id',$cp_id)
                ->field('user_id,user_username,user_image')
                ->find();
            if($have){
                return [];
            }else{
                $chargeShi = Db::table('up_u_user')
                    ->where('user_id',$user_id)
                    ->value('user_charge_shis');
                if(!$chargeShi){
                    return [];
                }
                $where = [
                    'user_status' => 1
                ];
                $chargeShi = trim($chargeShi,',');
                $moredata = explode(',',$chargeShi);
                if(count($moredata) > 1){
                    $we1 = array();
                    foreach($moredata  as $vo){
                        $we1[] = ['like',"%,$vo,%"];
                    }
                    $where['user_charge_shis'] = [$we1,'AND'];
                }else{
                    $where['user_charge_shis'] = ['like','%,'.$moredata[0].',%'];
                }
                $haveUser = Db::table('up_u_user')
                    ->where($where)
                    ->where('user_type',2)
                    ->where('user_hospital',$c_id)
                    ->column('user_id');
                $have = [];
                if($haveUser){
                    $have = Db::table('up_user_charge')->alias('uc')
                        ->join('up_u_user u','uc.uc_user_id=u.user_id','LEFT')
                        ->where('uc_user_id','in',$haveUser)
                        ->where('uc_cp_id',$cp_id)
                        ->field('user_id,user_username,user_image')
                        ->order('user_auth asc')
                        ->find();
                }
                if($have){
                    return $have;
                }else{
                    return [];
                }
            }
        }

    }
}